package com.ehelper.action;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.ehelper.model.Admin;
import com.ehelper.model.User;
import com.ehelper.service.AdminService;
import com.opensymphony.xwork2.ActionSupport;

@Component("download")
@Scope("prototype")
public class DownloadAction extends ActionSupport implements SessionAware 
{
	
	private static final long serialVersionUID=-146840963599059850L;
	private Map<String,Object> session;

	private InputStream fileInputStream;
	
	private String fileName;
	
	public InputStream getFileInputStream() {
		return fileInputStream;
	}


	public void setFileInputStream(InputStream fileInputStream) {
		this.fileInputStream = fileInputStream;
	}

	

	public String getFileName() {
		return fileName;
	}


	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		File file=new File(ServletActionContext.getServletContext().getRealPath("/file/help.txt"));
		
		fileName=file.getName();
		System.out.println(fileName);
		fileInputStream=new FileInputStream(file);
		
		return SUCCESS;
	}


	@Override
	public void setSession(Map<String, Object> arg0) {
		this.session=arg0;
	}	
	
	
}
